package com.springboot.demo.mapper;

import com.springboot.demo.entity.ReturnMsg;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ReturnManageMapper {
    @Select("SELECT * FROM returntable WHERE state='returning'")
    List<ReturnMsg> getAllreturnMsg();

    @Insert("insert into finerecord values(#{phone},#{fine},'sending',#{time},#{bookid})")
    void insertfine(String phone,int fine,String time,long bookid);

    @Update("update borrow set state='returned' where phone=#{phone} and ID=#{bookid} and start_time=#{starttime}")
    void updateborrow(String phone,long bookid,String starttime);

    @Update("update returntable set state='returned' where phone=#{phone} and ID=#{bookid} and start_time=#{starttime}")
    void updatereturn(String phone,long bookid,String starttime);

    @Update("update book set situation='not borrow' where ID=#{bookid}")
    void returnbook(long bookid);

    @Select("select * from returntable where phone=#{phone} and state='returned' limit #{currIndex},#{pageSize}")
    List<ReturnMsg> selectByPageNumAndPageSize(@Param("currIndex")int currIndex, @Param("pageSize")int pageSize, @Param("phone")String phone);

    @Select("select count(*) from returntable where phone=#{phone} and state='returned'")
    int selectAllRecordCount(@Param("phone") String phone);

}
